package com.ztf.parallel;

import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

public class ParallelTest {
    @Test
    public void testDeploy(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        processEngine.getRepositoryService()
                .createDeployment()
                .addClasspathResource("com/itheima09/activiti5/parallel/parallel.bpmn")
                .deploy();
    }

    @Test
    public void testStartPI(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        ProcessInstance pi = processEngine.getRuntimeService()
                //.startProcessInstanceByKey(processDefinitionKey)  根据pdkey启动流程实例  默认根据最高版本的启动
                .startProcessInstanceById("parallel:1:4604");
    }

    /**
     * 根据piid过滤任务
     */
    @Test
    public void testQueryTaskByPIID(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        List<Task> tasks = processEngine.getTaskService()
                .createTaskQuery()
                .processInstanceId("4701")
                .list();
        for (Task task : tasks) {
            System.out.println(task.getName());
        }
    }

    /**
     * executionID过滤任务
     */
    @Test
    public void testQueryTaskByExecutionID(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        Task task = processEngine.getTaskService()
                .createTaskQuery()
                .executionId("4704")
                .singleResult();

        System.out.println(task.getName());

    }
}
